import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Max } from '../Schema/max.schema'
import { Model } from 'mongoose'
@Injectable()
export class MaxService {
    constructor(@InjectModel(Max.name) private MaxModel: Model<Max>) {
    }
    async gettypelist() {
        return await this.MaxModel.find()
    }
    async add(req, res) {
        console.log(req.body)
        await this.MaxModel.create(req.body)
        res.send({
            code: 200,
            msg: '添加成功'
        })
    }
    async gets(req, res) {
        let { name } = req.body
        console.log(req.body);
        const result = await this.MaxModel.find({ name: { $regex: name } })
        res.send({
            code: 200,
            msg: '查询成功',
            data: result
        })
    }
    async editmax(req, res) {
        await this.MaxModel.updateOne({ _id: req.body._id }, req.body)
        res.send({
            code: 200,
            msg: '修改成功'
        })
    }
    async del(req, res) {
        await this.MaxModel.deleteOne({ _id: req.body._id })
        res.send({
            code: 200,
            msg: '删除成功'
        })
    }
}
